home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-03-17 | 4.1 KB | 185 lines | [TEXT/CWIE] |
- //
- // CFlyThroughDoc.cp
- //
- // A document class for opening a 3DMF file for viewing.
- //
- // by James Jennings
- // Started February 28, 1997
- //
-
- #include "CFlyThroughDoc.h"
- #include "C3DMFReader.h"
- #include "Q3AutoObject.h"
-
- #ifdef HAS_NEW_SCENE_MENU
- #include "CTriGridBox.h"
- #include "CBoxArrayMaker.h"
- #include "CScatteredBoxMaker.h"
- #endif // HAS_NEW_SCENE_MENU
-
- const OSType fileType_Creator = 'Fly3';
- const OSType fileType_3DMetafile = '3DMF';
-
- const ResIDT window_VehicleView = 1001;
- const PaneIDT pane_VehicleView = 'VehV';
- const PaneIDT slider_Thrust = 'Thru';
-
- CFlyThroughDoc::CFlyThroughDoc(LCommander *inSuper, FSSpec *inFSSpec)
- : LSingleDoc(inSuper)
- {
- Assert_(inFSSpec != nil);
-
- CVehicleViewPane *thePane = MakeWindow();
- mWindow->SetDescriptor(inFSSpec->name);
-
- // read and install the 3DMF file
-
- ::SetCursor( *::GetCursor(watchCursor) );
-
- C3DMFReader theModel(inFSSpec);
-
- thePane->SetModel(theModel.Get());
-
- // If there are no view hints, view from the front.
- if (theModel.GetViewHints() == nil)
- thePane->ProcessCommand(cmd_ViewFromFront);
- else // assume that the view hints specify a camera
- thePane->SetViewHints(theModel.GetViewHints());
-
-
- thePane->Refresh();
- mWindow->Show();
- }
-
- #ifdef HAS_NEW_SCENE_MENU
- CFlyThroughDoc::CFlyThroughDoc(LCommander *inSuper, CommandT inCommand)
- : LSingleDoc(inSuper)
- {
- CVehicleViewPane *thePane = MakeWindow();
-
- // build the scene that corresponds to the command
- switch ( inCommand ) {
- case cmd_8Cubes:
- {
- CBoxArrayMaker maker(2);
- thePane->SetModel( maker.Get() );
- }
- break;
- case cmd_27Cubes:
- {
- CBoxArrayMaker maker(3);
- thePane->SetModel( maker.Get() );
- }
- break;
- case cmd_64Cubes:
- {
- CBoxArrayMaker maker(4);
- thePane->SetModel( maker.Get() );
- }
- break;
- case cmd_Scatter20Box:
- {
- CScatteredBoxMaker maker;
- thePane->SetModel( maker.Get() );
- }
- break;
- case cmd_Scatter40Box:
- {
- CScatteredBoxMaker maker(40);
- thePane->SetModel( maker.Get() );
- }
- break;
- case cmd_TriGridBox10:
- {
- CTriGridBox maker(4,10);
- thePane->SetModel( maker.Get() );
- }
- break;
- case cmd_TriGridBox30:
- {
- CTriGridBox maker(4,30);
- thePane->SetModel( maker.Get() );
- }
- break;
- default:
- Assert_(false /* new document called with unknown command */);
- }
-
- thePane->Refresh();
- mWindow->Show();
-
- }
- #endif // HAS_NEW_SCENE_MENU
-
- CVehicleViewPane * CFlyThroughDoc::MakeWindow()
- {
- mWindow = LWindow::CreateWindow(window_VehicleView, this);
- Assert_( mWindow != nil );
-
- // Arrange for the QuickDraw 3D view to receive commands.
- CVehicleViewPane *thePane = (CVehicleViewPane*)
- mWindow->FindPaneByID( pane_VehicleView );
- Assert_( thePane != nil );
-
- mWindow->SetLatentSub( thePane );
-
- // Connect the Thrust slider to the Vehicle
-
- LControl *theSlider = (LControl*) mWindow->FindPaneByID( slider_Thrust );
- theSlider->AddListener( thePane->GetVehicle() );
-
- return thePane;
- }
-
- void CFlyThroughDoc::DoAESave( FSSpec &inFileSpec, OSType inFileType )
- {
- // Create the new file.
- LFile macFile( inFileSpec );
- macFile.CreateNewFile( fileType_Creator, fileType_3DMetafile );
-
- // Create storage and file objects, and link them
- Q3AutoObject<TQ3StorageObject> theStorage( ::Q3FSSpecStorage_New( &inFileSpec ) );
- ThrowIfNil_(theStorage.Get());
-
- Q3AutoObject<TQ3FileObject> theFile(::Q3File_New());
- ThrowIfNil_(theFile.Get());
-
- TQ3Status theStatus;
- theStatus = ::Q3File_SetStorage(theFile, theStorage);
- ThrowIfQ3Fail_(theStatus);
-
- // Open the file...
- if ( ::Q3File_OpenWrite(theFile,
- kQ3FileModeNormal /*| kQ3FileModeText*/) == kQ3Success ) {
-
- Assert_( mWindow != nil );
- CVehicleViewPane *thePane = (CVehicleViewPane*)
- mWindow->FindPaneByID( pane_VehicleView );
- Assert_( thePane != nil );
-
- // ... and write to it
- thePane->Write(theFile);
-
- // To do: View Hints.
-
- theStatus = ::Q3File_Close( theFile );
- // ThrowIfQ3Fail_(theStatus);
-
- } else {
- // post error alert
- TQ3Error q3Err;
- q3Err = ::Q3Error_Get( &q3Err );
- switch (q3Err) {
- case kQ3ErrorMacintoshError:
- OSErr macErr;
- ::Q3MacintoshError_Get( &macErr );
- // ...
- break;
- case kQ3ErrorOutOfMemory:
- default: // unknown error
- break;
- }
-
- }
- }
-